package com.ncloud.crm.mapper;

import com.ncloud.crm.entity.BsDiscntFee;
import org.apache.ibatis.annotations.*;

/**
 * Created by shiqiang on 2017/5/12.
 */
@Mapper
public interface BsDiscntFeeMapper {
    @Select(value = { "select * from bs_discnt_fee where discnt_inst_id = #{discntInstId} and  now() between begin_date and end_date" })
    @Results({ @Result(column = "discnt_inst_id", property = "discntInstId"),@Result(column = "cust_id", property = "custId"),
            @Result(column = "discnt_id", property = "discntId"),@Result(column = "discnt_name", property = "discntName"),
            @Result(column="fee_type",property="feeType"),@Result(column="fee_code",property="feeCode"),
            @Result(column="pay_type",property="payType"),@Result(column="received_fee",property="receivedFee"),
            @Result(column="pay_fee",property="payFee"),@Result(column="balance",property="balance"),
            @Result(column="standard",property="standard"),@Result(column="billing_cycle",property="billingCycle"),
            @Result(column="cycle_unit",property="cycleUnit"),
            @Result(column="end_date",property="endDate"),@Result(column="update_time",property="updateTime"),
            @Result(column="create_time",property="createTime"),@Result(column="create_user",property="createUser"),
            @Result(column="fee_value",property="feeValue"),@Result(column="fee_value2",property="feeValue2"),
            @Result(column="str_value",property="strValue"),@Result(column="str_value2",property="strValue2")
    })
    public BsDiscntFee getBsDiscntFeeByPk(Long discntInstId);
    
    @Select(value = { "select cust_id,discnt_inst_id,discnt_id,discnt_name,fee_type,fee_code,pay_type,received_fee"
    		+ ",pay_type,balance,standard,billing_cycle,cycle_unit,begin_date,end_date,create_user,create_time,"
    		+ "fee_value,fee_value2,str_value,str_value2 from bs_discnt_fee where discnt_inst_id = #{discntInstId} "
    		+ "and  now() between begin_date and end_date union select cust_id,discnt_inst_id,discnt_id,discnt_name"
    		+ ",fee_type,fee_code,pay_type,received_fee,pay_type,balance,standard,billing_cycle,cycle_unit,begin_date"
    		+ ",end_date,create_user,create_time,fee_value,fee_value2,str_value,str_value2 from bs_o_discnt_fee where"
    		+ " discnt_inst_id = #{discntInstId} and  now() between begin_date and end_date" })
    @Results({ @Result(column = "discnt_inst_id", property = "discntInstId"),@Result(column = "cust_id", property = "custId"),
            @Result(column = "discnt_id", property = "discntId"),@Result(column = "discnt_name", property = "discntName"),
            @Result(column="fee_type",property="feeType"),@Result(column="fee_code",property="feeCode"),
            @Result(column="pay_type",property="payType"),@Result(column="received_fee",property="receivedFee"),
            @Result(column="pay_fee",property="payFee"),@Result(column="balance",property="balance"),
            @Result(column="standard",property="standard"),@Result(column="billing_cycle",property="billingCycle"),
            @Result(column="cycle_unit",property="cycleUnit"),
            @Result(column="end_date",property="endDate"),@Result(column="update_time",property="updateTime"),
            @Result(column="create_time",property="createTime"),@Result(column="create_user",property="createUser"),
            @Result(column="fee_value",property="feeValue"),@Result(column="fee_value2",property="feeValue2"),
            @Result(column="str_value",property="strValue"),@Result(column="str_value2",property="strValue2")
    })
    public BsDiscntFee getBsDiscntOFeeByPk(Long discntInstId);

    @Insert("insert into bs_discnt_fee(cust_id,discnt_inst_id,discnt_id,discnt_name,fee_type,fee_code," +
            "pay_type,received_fee,pay_fee,balance,standard,billing_cycle,cycle_unit,begin_date,end_date,create_time,create_user," +
            "fee_value,fee_value2,str_value,str_value2) values(#{custId},#{discntInstId},#{discntId},#{discntName},#{feeType},#{feeCode}," +
            "#{payType},#{receivedFee},#{payFee},#{balance},#{standard},#{billingCycle},#{cycleUnit},#{beginDate},#{endDate},#{createTime},#{createUser}," +
            "#{feeValue},#{feeValue2},#{strValue},#{strValue2})")
    int insertBsDiscnt(BsDiscntFee bsDiscntFee);

    @Update("update bs_discnt_fee set end_date=#{endDate},update_time=#{updateTime},"
            + "update_user=#{updateUser} where discnt_inst_id=#{discntInstId} and begin_date = #{beginDate}")
    int updateBsDiscnt(BsDiscntFee bsDiscntFee);
}
